import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: xiaotutu
 * Date: 2023-12-02
 * Time: 13:22
 */

class Person {
    public String name;
    public int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
}

public class Test {

    public static void main(String[] args) {
        String str = "hello";
        String ret1 = str.substring(1);//截取指定位置开始的剩余字符串
        System.out.println(ret1);
        System.out.println("=====");
        String ret2 = str.substring(1,3);//[1,3)
        System.out.println(ret2);

        System.out.println("====");
        String str4 = "   hell  oo  p   0   pppp";
        System.out.println(str4.trim());
        System.out.println(str4);
    }

    public static void main7(String[] args) {
        /*String str = "hello world hello bit";
        String[] ret = str.split(" ",2);
        for (int i = 0; i < ret.length; i++) {
            System.out.println(ret[i]);
        }
        System.out.println("==============");
        String str2 = "192.168.0.0.1";
        String[] ret2 = str2.split("\\.");
        for (int i = 0; i < ret2.length; i++) {
            System.out.println(ret2[i]);
        }*/

        /*String str2 = "192\\168\\0\\0\\1";
        String[] ret2 = str2.split("\\\\");
        for (int i = 0; i < ret2.length; i++) {
            System.out.println(ret2[i]);
        }*/

        /*String str2 = "name=zhangsan&age=18";
        String[] ret2 = str2.split("=|&");
        for (int i = 0; i < ret2.length; i++) {
            System.out.println(ret2[i]);
        }*/
        /*String str2 = "name=zhangsan&age=18";
        String[] ret2 = str2.split("&");
        for (int i = 0; i < ret2.length; i++) {
            //System.out.println(ret2[i]);
            String[] strings = ret2[i].split("=");
            for (String s : strings) {
                System.out.println(s);
            }
        }*/
    }

    public static void main6(String[] args) {
        String str1 = "ababcabcdabcdeabcdef";
        String ret = str1.replaceFirst("ab","ooo");
        System.out.println(ret);
        System.out.println("==============");
        String ret2 = str1.replaceAll("ab","ooo");
        System.out.println(ret2);
        System.out.println("==============");
        String ret3 = str1.replace("ab","ooo");
        System.out.println(ret3);
        System.out.println("==============");
        String ret4 = str1.replace('a','p');
        System.out.println(ret4);
    }

    public static void main5(String[] args) {
        String str = "hello";
        String ret = str.toUpperCase();//所有对String的修改,都不是在原来值的基础上
        System.out.println(ret);       //而是创建一个新的对象
        System.out.println("=========");
        String str2 = "ABCDE";
        System.out.println(str2.toLowerCase());
        System.out.println("=========");
        String str3 = "helloworld";
        char[] array = str3.toCharArray();
        System.out.println(Arrays.toString(array));

        System.out.println("=============");
        String ret2 = String.format("%d,%d,%d",10,20,30);
        System.out.println(ret2);
    }

    public static void main4(String[] args) {
        String s1 = String.valueOf(1234);
        System.out.println(s1);

        String s2 = String.valueOf(new Person("zhangsan",10));
        System.out.println(s2);

        System.out.println("==========");
        int data1 = Integer.valueOf("123");
        int data2 = Integer.parseInt("123");
        System.out.println(data2);
    }

    public static void main3(String[] args) {
        String str1 = "hello";
        char ch = str1.charAt(1);
        System.out.println(ch);
        System.out.println(str1.indexOf('l'));
        System.out.println(str1.indexOf('e',3));
        System.out.println(str1.indexOf("ll"));
        System.out.println("===========");
        System.out.println(str1.lastIndexOf('l'));
        System.out.println(str1.lastIndexOf('l',2));
    }

    public static void main2(String[] args) {
        String str1 = new String("hello");
        String str2 = new String("hello");
        System.out.println(str1 == str2);
        System.out.println(str1.equals(str2));
        System.out.println("=========");
        String str3 = "abc";
        String str4 = "abc";
        System.out.println(str3 == str4);

        System.out.println("====");
        String str5 = "abc";
        String str6 = "abD";

        System.out.println(str5.compareTo(str6));
        System.out.println(str5.compareToIgnoreCase(str6));
    }


    public static void main1(String[] args) {
        String str1 = "hello";
        String str2 = new String("hello");
        char[] chars = {'a','b','c','d'};
        String str3 = new String(chars);
        System.out.println(str3);
        System.out.println(str1);
        System.out.println(str2);
        System.out.println(str1.length());
        System.out.println(str2.length());
        System.out.println("===========");
        String str4 = "";
        System.out.println(str4.isEmpty());
        String str5 = null;
        System.out.println(str5.isEmpty());
    }
}
